#define  _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
struct ListNode {
    int val;
    struct ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};
class PalindromeList {
public:
    struct ListNode* middleNode(struct ListNode* head)
    {
        struct ListNode* fast = head;
        struct ListNode* slow = head;
        while (fast && fast->next)
        {
            slow = slow->next;
            fast = fast->next;
        }
        return slow;
    }
    struct ListNode* reverseList(struct ListNode* head)
    {
        if (head == NULL)
            return NULL;
        struct ListNode* n1, * n2, * n3;
        n1 = NULL;
        n2 = head;
        n3 = n2->next;
        while (n2)
        {
            n2->next = n1;
            n1 = n2;
            n2 = n3;
            if (n3)
                n3 = n2->next;
        }
        return n1;
    }

    bool chkPalindrome(ListNode* A)
    {
        ListNode* mid = middleNode(A);
        ListNode* rhead = reverseList(mid);
        ListNode* curA = A;
        ListNode* curR = rhead;
        while (curA && curR)
        {
            if (curA->val != curR->val)
                return false;
            curA = curA->next;
            curR = curR->next;
        }
        return true;
    }
};